<?php


namespace App\Admin\Show;

use App\Models\XxCapitalFlow;
use App\Models\XxPushTask;
use Encore\Admin\Widgets\Table;
use Illuminate\Contracts\Support\Renderable;


class Capitals implements Renderable
{
    public function render($key = null)
    {
        $task_id = XxPushTask::where('id', $key)->value('task_id');
        $capitals = $capitals = XxCapitalFlow::selectRaw("merchant_capital_change,
                merchant_commission_change, uid,
                CASE finance_type
                WHEN 1 THEN '商家销量推广本金佣金扣除'
                WHEN 2 THEN '商家销量推广冻结本金佣金扣除'
                WHEN 3 THEN '推手销量任务收入本金佣金'
                WHEN 4 THEN '师傅销量任务收入佣金'
                WHEN 5 THEN '师公销量任务收入佣金'
                WHEN 6 THEN '平台销量佣金收入'
                WHEN 7 THEN '商家销量推广本金佣金退还'
                WHEN 8 THEN '推手销量任务退还本金佣金'
                WHEN 9 THEN '师父销量佣金退还'
                WHEN 10 THEN '师公销量佣金退还'
                WHEN 11 THEN '平台销量佣金退还'
                WHEN 12 THEN '销量审核失败本金佣金退还'
                WHEN 13 THEN '商家充值冻结增加'
                WHEN 14 THEN '商家充值审核通过余额增加'
                WHEN 15 THEN '商家充值审核失败冻结余额减少'
                WHEN 16 THEN '商家流量推广本金佣金扣除'
                WHEN 17 THEN '商家流量推广冻结本金佣金扣除'
                WHEN 18 THEN '推手流量任务收入本金佣金'
                WHEN 19 THEN '平台流量佣金收入'
                WHEN 20 THEN '商家流量推广本金佣金退还'
                WHEN 21 THEN '推手流量任务退还本金佣金'
                WHEN 22 THEN '平台销量佣金退还'
                WHEN 23 THEN '流量审核失败'
                WHEN 24 THEN '推手本金提现成功扣款'
                WHEN 25 THEN '推手本金提现失败退还'
                WHEN 26 THEN '推手佣金提现成功扣款'
                WHEN 27 THEN '推手佣金提现失败退还'
                WHEN 48 THEN '推手佣金提现冻结佣金增加'
                WHEN 49 THEN '推手本金提现冻结本金增加'
                WHEN 28 THEN '管理员操作'
                WHEN 29 THEN '商家提现余额减少冻结余额增加'
                WHEN 30 THEN '商家提现审核通过冻结余额减少'
                WHEN 31 THEN '商家提现审核失败冻结余额减少余额增加'
                WHEN 32 THEN '商家评价推广本金扣除'
                WHEN 33 THEN '商家评价推广冻结本金扣除'
                WHEN 34 THEN '推手评价任务收入佣金'
                WHEN 35 THEN '平台评价佣金收入'
                WHEN 36 THEN '商家评价推广佣金退还'
                WHEN 37 THEN '推手评价任务退还佣金'
                WHEN 38 THEN '平台评价佣金退还'
                WHEN 39 THEN '评价任务审核失败'
                WHEN 40 THEN '购买商品'
                END as finance_type, capital_balance,
                commission_balance, capital_change, commission_change,
                extra_commission_change, referral_change, freeze_balance, freeze_balance_change,
                FROM_UNIXTIME(create_time)")
            ->where('task_id', $task_id)->get();
        if (!empty($capitals)) {
            $table = new Table([
                '商户本金变动', '商户佣金变动', '刷手ID', '财务类型',
                '余额', '佣金余额', '本金变动', '佣金变动', '额外佣金变动', '推荐金变动',
                '冻结余额', '冻结余额变动', '创建时间'
            ], $capitals->toArray());
            echo $table->render();
        }
    }
}
